<!-- 询价管理 -->
<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      :page.sync="page"
      v-model="form"
      ref="crud"
      @search-change="searchChange"
      @search-reset="searchReset"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template slot-scope="{ row }" slot="inquiryValidity">
        {{ `${row.rfqStart || "-"} 至 ${row.rfqEnd || "-"}` }}
      </template>
      <template slot-scope="{ row }" slot="vofValidity">
        {{ `${row.validityStartTs || "-"} 至 ${row.validityEndTs || "-"}` }}
      </template>
      <template slot-scope="{ row }" slot="menu">
        <el-button
          type="text"
          size="mini"
          icon="el-icon-view"
          @click.stop="view(row)"
          >详情</el-button
        >
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
import { getList } from "@/api/inquiry/index";
import { mapGetters } from "vuex";

export default {
  data() {
    return {
      form: {},
      query: {},
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      data: [],
    };
  },
  components: {},
  computed: {
    ...mapGetters(["permission"]),
    option() {
      return {
        height: "auto",
        calcHeight: 30,
        tip: false,
        searchShow: false,
        searchMenuSpan: 6,
        border: true,
        labelWidth: "180",
        menuWidth: "250",
        addBtn: false,
        delBtn: false,
        editBtn: false,
        column: [
          {
            label: "ID",
            prop: "id",
          },
          {
            label: "承运商",
            prop: "partyName",
            search: this.vaildData(this.permission.tms_inquiry_carrier, false),
            showColumn: !this.vaildData(
              this.permission.tms_inquiry_carrier,
              true
            ),
            hide: !this.vaildData(this.permission.tms_inquiry_carrier, false),
          },
          {
            label: "状态",
            prop: "enquiryStatus",
            type: "select",
            props: {
              label: "value",
              value: "key",
            },
            search: true,
            dicUrl: `/api/blade-tms/common/SelectEnum?name=EnquiryStatus`,
          },
          {
            label: "询价单号",
            prop: "fagrmntid044",
            search: true,
          },
          {
            label: "询价描述",
            prop: "fagrmntid044Text",
            search: true,
          },
          {
            label: "询价有效期",
            prop: "inquiryValidity",
          },
          // {
          //   label: "币别",
          //   prop: "docCurrency",
          // },
          {
            label: "货运协议有效期",
            prop: "vofValidity",
          },
          {
            label: "询价响应截止日期",
            prop: "responseEnd",
          },
          {
            label: "询价有效期-开始",
            type: "datetime",
            prop: "rfqStart",
            search: true,
            searchLabelWidth: "150",
            searchRange: true,
            editDisplay: false,
            hide: true,
            showColumn: false,
            defaultTime: ["00:00:00", "23:59:59"],
            format: "yyyy-MM-dd HH:mm:ss",
            valueFormat: "yyyy-MM-dd HH:mm:ss",
            startPlaceholder: "请选择开始日期",
            endPlaceholder: "请选择结束日期",
          },
          {
            label: "询价有效期-结束",
            type: "datetime",
            prop: "rfqEnd",
            search: true,
            searchLabelWidth: "150",
            searchRange: true,
            editDisplay: false,
            hide: true,
            showColumn: false,
            defaultTime: ["00:00:00", "23:59:59"],
            format: "yyyy-MM-dd HH:mm:ss",
            valueFormat: "yyyy-MM-dd HH:mm:ss",
            startPlaceholder: "请选择开始日期",
            endPlaceholder: "请选择结束日期",
          },
          {
            label: "询价响应截止日期",
            type: "datetime",
            prop: "responseTime",
            search: true,
            searchLabelWidth: "150",
            searchRange: true,
            editDisplay: false,
            hide: true,
            showColumn: false,
            defaultTime: ["00:00:00", "23:59:59"],
            format: "yyyy-MM-dd HH:mm:ss",
            valueFormat: "yyyy-MM-dd HH:mm:ss",
            startPlaceholder: "请选择开始日期",
            endPlaceholder: "请选择结束日期",
          },
        ],
      };
    },
  },
  methods: {
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      let query = Object.assign(params, this.query);
      if (query.rfqStart) {
        query = {
          ...query,
          rfqStart: {
            start: query.rfqStart ? query.rfqStart[0] : "",
            end: query.rfqStart ? query.rfqStart[1] : "",
          },
        };
        delete query.rfqStart;
      }
      if (query.rfqEnd) {
        query = {
          ...query,
          rfqEnd: {
            start: query.rfqEnd ? query.rfqEnd[0] : "",
            end: query.rfqEnd ? query.rfqEnd[1] : "",
          },
        };
        delete query.rfqEnd;
      }
      if (query.responseTime) {
        query = {
          ...query,
          responseEnd: {
            start: query.responseTime ? query.responseTime[0] : "",
            end: query.responseTime ? query.responseTime[1] : "",
          },
        };
        delete query.responseTime;
      }
      this.loading = true;
      getList(page.currentPage, page.pageSize, query).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.$nextTick(() => {
          this.$refs.crud.$refs.table.doLayout();
        });
      });
    },
    view(row) {
      this.$router.push({ path: `/inquiry/details?id=${row.id}` });
    },
  },
};
</script>

<style></style>
